package com.zhangwei.yueshijia.view.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;

import com.superrecycleview.superlibrary.adapter.BaseViewHolder;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;
import com.zhangwei.yueshijia.R;
import com.zhangwei.yueshijia.bean.home.Goods;
import com.zhangwei.yueshijia.utils.ImageLoader;

import java.util.List;


public class GoodsAdapter extends SuperBaseAdapter<Goods> {
    private static final String ITEM_TYPE2 = "2";
    private static final String ITEM_TYPE4 = "4";
    private static final String ITEM_TYPE7 = "7";
    private static final String ITEM_TYPE6 = "6";
    private static final String ITEM_TYPE1 = "1";

    private Context context;
    GoodsSpecialAdapter adapter;

    public GoodsAdapter(Context context, List<Goods> data) {
        super(context, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder holder, Goods item, int position) {

        if (item.getRelationObjectType().equals(ITEM_TYPE4)) {
            holder.setText(R.id.item_goods_type4_title, item.getRelationObjectTitle());
            ImageLoader.getSingleton().displayBlurImage(context ,item.getRelationObjectImage(), holder.getView(R.id.item_goods_type4_img));
            RecyclerView rv = holder.getView(R.id.item_goods_type4_rv);
            if (adapter == null) {
                rv.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
                adapter = new GoodsSpecialAdapter(context);
                rv.setAdapter(adapter);
            } else {
                adapter.mData.clear();
            }
            adapter.mData.addAll(item.getGoodsSpecialList());
            adapter.notifyDataSetChanged();
        } else {
            holder.setText(R.id.item_goods_title, item.getRelationObjectTitle())
                    .setText(R.id.item_goods_price, item.getGoodsPrice())
                    .setText(R.id.item_goods_content, item.getRelationObjectJingle());
            ImageLoader.getSingleton().displayImage(item.getRelationObjectImage(), context, holder.getView(R.id.item_goods_img));
        }

    }

    @Override
    protected int getItemViewLayoutId(int position, Goods item) {
        String type = item.getRelationObjectType();
        if (!TextUtils.isEmpty(type) && type.equals(ITEM_TYPE4)) {
            return R.layout.item_goods_type4_layout;
        }
//        else if (!TextUtils.isEmpty(type) && type.equals(ITEM_TYPE6)) {
//            return R.layout.item_goods_type6_layout;
//        } else if (!TextUtils.isEmpty(type) && type.equals(ITEM_TYPE4)) {
//            return R.layout.item_goods_type4_layout;
//        } else if (!TextUtils.isEmpty(type) && type.equals(ITEM_TYPE1)) {
//            return R.layout.item_goods_default_layout;
//        } else if (!TextUtils.isEmpty(type) && type.equals(ITEM_TYPE2)) {
//            return R.layout.item_goods_default_layout;}
        else {
            return R.layout.item_goods_default_layout;
        }
    }

}
